package servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import session.AppointmentDao;

 
/**
 * Kontroller za listanje budućih termina
 * priprema podatke listAppontments.jsp
 * 
 * @author rigo & jung
 *
 */
public class ListAppointments extends HttpServlet {
	private static final long serialVersionUID = -9026278194446517234L;
	
	@EJB
	protected AppointmentDao appointmentDao ;
	 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			if(request.getSession().getAttribute("user")==null){
				response.sendRedirect(response.encodeURL("./login.jsp"));
				return;
			}
			request.setAttribute("appointments", appointmentDao.listAllAvailable());
			getServletContext().getRequestDispatcher("/listAppointments.jsp").forward(request, response);
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
